#include "apue.h"

void set_fl(int fd, int flags) {
	int val;
	if ((val = fcntl(fd, F_GETFL)) < 0) {
		err_sys("fcntl error F_GETFL");
	}

	val |= flags;
	if (fcntl(fd, F_SETFL, val) < 0) {
		err_sys("fcntl error F_SETFL");
	}
}

void main() {
	int fd = open("test", O_RDWR);
	set_fl(fd, O_RDONLY);
	int re = fcntl(fd, F_GETFL);
	re &= O_ACCMODE;
	printf("re = %d\n", re);
}
